﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using System.Diagnostics;

namespace Lilium.UI
{
	public abstract class FieldAdapterBase: IFieldAdapter
	{
		public FieldAdapterBase(
			Type fieldType,
			IFieldValueConverter converter)
		{
			if (fieldType == null) throw new ArgumentNullException("fieldType");
			if (converter == null) throw new ArgumentNullException("converter");

			m_Converter = converter;
			m_FieldType = fieldType;
		}

		#region IFieldAdapter Members

		public abstract bool Enabled
		{
			get;
			set;
		}

		public object Value
		{
			get
			{
				return GetValue();
			}
			set
			{
				SetValue(value);
			}
		}

		#endregion

		protected abstract object GetValue();

		protected abstract void SetValue(object value);

		#region protected IFieldValueConverter Converter

		private readonly IFieldValueConverter m_Converter;

		protected IFieldValueConverter Converter
		{
			[DebuggerNonUserCodeAttribute]
			get
			{
				return m_Converter;
			}
		}

		#endregion

		#region public Type FieldType

		private readonly Type m_FieldType;

		public Type FieldType
		{
			[DebuggerNonUserCodeAttribute]
			get
			{
				return m_FieldType;
			}
		}

		#endregion
	}
}